package com.ruoyi.project.data.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.service.PermissionService;
import com.ruoyi.project.data.domain.WeightCarEnter;
import com.ruoyi.project.data.service.IWeightCarEnterService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 车辆进场记录Controller
 *
 * @author ruoyi
 * @date 2020-03-24
 */
@RestController
@RequestMapping("/system/enter")
public class WeightCarEnterController extends BaseController
{
    @Autowired
    private IWeightCarEnterService weightCarEnterService;
    @Autowired
    private PermissionService permissionService;

    /**
     * 查询车辆进场记录列表
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeightCarEnter weightCarEnter)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        weightCarEnter.setStationId(stationId);
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        weightCarEnter.setAreas(areas);
        weightCarEnter.setManagementCharacters(managementCharacters);
        startPage();
        List<WeightCarEnter> list = weightCarEnterService.selectWeightCarEnterList(weightCarEnter);
        return getDataTable(list);
    }

    /**
     * 导出车辆进场记录列表
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:export')")
    @Log(title = "车辆进场记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WeightCarEnter weightCarEnter)
    {
        List<WeightCarEnter> list = weightCarEnterService.selectWeightCarEnterList(weightCarEnter);
        ExcelUtil<WeightCarEnter> util = new ExcelUtil<WeightCarEnter>(WeightCarEnter.class);
        return util.exportExcel(list, "enter");
    }

    /**
     * 获取车辆进场记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(weightCarEnterService.selectWeightCarEnterById(id));
    }

    /**
     * 新增车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:add')")
    @Log(title = "车辆进场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeightCarEnter weightCarEnter)
    {
        return toAjax(weightCarEnterService.insertWeightCarEnter(weightCarEnter));
    }

    /**
     * 修改车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:edit')")
    @Log(title = "车辆进场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeightCarEnter weightCarEnter)
    {
        return toAjax(weightCarEnterService.updateWeightCarEnter(weightCarEnter));
    }

    /**
     * 删除车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('weight:enter:remove')")
    @Log(title = "车辆进场记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weightCarEnterService.deleteWeightCarEnterByIds(ids));
    }

    /**
     *  获取场站视频地址-回放
     * @param stationId
     * @return
     */
    @GetMapping("/getBackVideoPath")
    public AjaxResult getBackVideoPath(@Param(value="id") Long id)
    {
        return  weightCarEnterService.getBackVideoPath(id);
    }

    @GetMapping("/getVideoPath")
    public AjaxResult getVideoPath(@Param(value="id") Long id)
    {
        return  weightCarEnterService.getVideoPath(id);
    }
}
